package blocksim.hash;

import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class HashAlgorithmsComparison {

  public static void main(String[] args) throws NoSuchAlgorithmException {

    String[] algorithms = { "SHA", "WRHF32", "RHF32"
    // ,"RHF64", "MD5"
    };

    for (int run = 1; run <= 30; run++) {

      for (int windowSize = 32; windowSize <= 4096; windowSize *= 2) {

        for (int bufferSize = 1; bufferSize <= windowSize; bufferSize += windowSize - 1) {

          for (int streamSize = 102400; streamSize <= 1024 * Math.pow(10, 6); streamSize *= 10) {
            byte[] buffer = new byte[bufferSize];
            long seed = System.nanoTime();
            for (String alg : algorithms) {
              Random random = new Random(seed);
              HashStrategy hashSt = HashStrategyFactory.getInstance(alg, windowSize);

              long initTime = System.currentTimeMillis();
              for (int i = 0; i < streamSize; i += bufferSize) {
                random.nextBytes(buffer);
                hashSt.pushBytes(buffer);
                if (bufferSize >= windowSize) {
                  // long addTime =
                  // System.currentTimeMillis();
                  hashSt.hash();
                }
              }
              long hashTime = System.currentTimeMillis();
              System.out.println(run + "\t" + windowSize + "\t" + bufferSize + "\t" + streamSize
                  + "\t" + alg + "\t" + (hashTime - initTime));
              // + "\t" + (addTime - initTime)
              // + "\t" + (hashTime - addTime));
            }
          }
        }
      }
    }
  }

}
